<template>
  <div class="container">
    <div class="apply-container">
      <div class="apply-container-head"></div>
      <div class="apply-container-body">
        <div class="apply-container-body-title">
          <div class="apply-container-body-title-font">修改驾驶员档案</div>
          <div class="apply-container-body-title-return">
            <el-button size="small" @click="goBackPage">返回</el-button>
          </div>
        </div>
        <el-divider class="apply-container-body-title-line"></el-divider>
        <div class="apply-container-body-content">
          <el-form :model="DriverArchives" label-width="100px" label-position="LabelPosition" ref="DriverArchives"
            :rules="DriverArchivesRules" style="width: 100%;">
            <el-form-item label="驾驶员工号:" prop="InputUserId" style="width: 40%;">
              <el-input disabled v-model="DriverArchives.InputUserId"></el-input>
            </el-form-item>
            <el-form-item label="姓名:" prop="InputDriverName" style="width: 40%;">
              <el-input disabled v-model="DriverArchives.InputDriverName" clearable></el-input>
            </el-form-item>
            <el-form-item label="准驾车型:" prop="InputLicenseType" style="width: 40%;">
              <el-input v-model="DriverArchives.InputLicenseType"></el-input>
            </el-form-item>
            <el-form-item label="驾龄:" prop="InputDriverAge" style="width: 40%;">
              <el-input v-model="DriverArchives.InputDrivingAge"></el-input>
            </el-form-item>
            <el-form-item label="联系方式:" prop="InputDriverPhone" style="width: 40%;">
              <el-input v-model="DriverArchives.InputDriverPhone"></el-input>
            </el-form-item>
            <el-form-item label="身份证号:" prop="InputDriverIdNumber" style="width: 40%;">
              <el-input disabled v-model="DriverArchives.InputDriverIdNumber"></el-input>
            </el-form-item>
            <el-form-item label="驾证有效期:" prop="InputDriverLicenseValidity" style="width: 40%;">
              <el-input v-model="DriverArchives.InputDriverLicenseValidity" clearable></el-input>
            </el-form-item>
            <div class="apply-container-body-content-submit">
              <el-button type="primary" @click="DriverArchiveUpdate('DriverArchives')">提交</el-button>
            </div>
          </el-form>
        </div>
      </div>
      <div class="apply-container-footer"></div>
    </div>
  </div>
</template>
  
<script>
import { driverArchiveUpdate } from "@/api/archives";

export default {
  name: 'UpgradeDriverArchives',
  data() {
    return {
      LabelPosition: 'right',
      DriverArchives: {
        InputUserId: null,
        InputDriverName: null,
        InputLicenseType: null,
        InputDrivingAge: null,
        InputDriverPhone: null,
        InputDriverIdNumber: null,
        InputDriverLicenseValidity: null,
      },
      DriverArchivesRules: {
        InputDriverName: [{ required: true, message: '请输入驾驶员姓名', trigger: 'blur' },],
        InputLicenseType: [{ required: true, message: '请选择驾驶证类型', trigger: 'blur' },],
        SelectUserId: [{ required: true, message: '请选择驾驶员工号', trigger: 'blur' },],
        InputDrivingAge: [{ required: true, message: '请输入驾龄', trigger: 'blur' },],
        InputDriverPhone: [{ required: true, message: '请输入驾驶员联系方式', trigger: 'blur' },],
        InputDriverIdNumber: [{ required: true, message: '请输入驾驶员身份证号', trigger: 'blur' },],
        DriverLicenseValidity: [{ required: true, message: '请输入驾驶证有效期', trigger: 'blur' },],
      },
      SubmitDriverArchive: {
        userId: null,
        driverName: null,
        licenseType: null,
        drivingAge: null,
        driverPhone: null,
        driverIdNumber: null,
        driverLicenseValidity: null
      }
    }
  },

  methods: {
    initFormDetail() {
      this.DriverArchives.InputUserId = this.$route.query.userId;
      this.DriverArchives.InputDriverName = this.$route.query.driverName;
      this.DriverArchives.InputLicenseType = this.$route.query.licenseType
      this.DriverArchives.InputDrivingAge = this.$route.query.drivingAge
      this.DriverArchives.InputDriverPhone = this.$route.query.driverPhone
      this.DriverArchives.InputDriverIdNumber = this.$route.query.driverIdNumber
      this.DriverArchives.InputDriverLicenseValidity = this.$route.query.driverLicenseValidity
    },

    DriverArchiveUpdate(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$confirm('此操作将修改此驾驶员档案, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {

            this.SubmitDriverArchive.driverIdNumber = this.DriverArchives.InputDriverIdNumber;
            this.SubmitDriverArchive.userId = this.DriverArchives.InputUserId;
            this.SubmitDriverArchive.driverName = this.DriverArchives.InputDriverName;
            this.SubmitDriverArchive.driverPhone = this.DriverArchives.InputDriverPhone;
            this.SubmitDriverArchive.driverLicenseValidity = this.DriverArchives.InputDriverLicenseValidity;
            this.SubmitDriverArchive.drivingAge = this.DriverArchives.InputDrivingAge;
            this.SubmitDriverArchive.licenseType = this.DriverArchives.InputLicenseType;

            driverArchiveUpdate(this.SubmitDriverArchive).then(res => {
              if (res.data.code === '0') {
                this.$message({
                  message: "修改成功",
                  duration: 2000,
                  showClose: true,
                  type: 'success'
                });

                this.goBackPage()

              }
              else {
                this.$message.error(res.data.msg);
              }
            }).catch((err) => {
              console.log(err)
            })

          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消'
            });
          });
        }
        else {
          return false;
        }
      })
    },
    goBackPage() {
      this.$router.go(-1)
    },
    GetAutoDriver() {
      //前后端连接
    },
  },

  mounted() {
    this.initFormDetail();
  },
}
</script>
  
<style scoped>
.container {
  height: 96%;
  width: 95%;
  margin: 0 auto;
  margin-top: 1%;
  background-color: #ffffff;
}

.apply-container {
  width: 90%;
  height: 100%;
  margin: 0 auto;
  /* background-color: #f2f2f2; */

}

.apply-container-head {
  width: 95%;
  height: 30px;
  margin: 0 auto;
}

.apply-container-body {
  width: 95%;
  height: 92%;
  margin: 0 auto;
  background-color: #ffffff;

}

.apply-container-body-title {
  width: 98%;
  height: 5%;
  margin: 0 auto;
  display: flex;
}

.apply-container-body-title-return {
  width: 100%;
  padding-top: 5px;
  display: flex;
  justify-content: flex-end;
}

.apply-container-body-title-line {
  height: 1px;
  width: 98%;
  margin: 5px auto;
}

.apply-container-body-title-font {
  width: 100%;
  height: 99%;
  font-size: 18px;
  font-weight: bold;
  text-align: left;
  padding-top: 10px;
}

.apply-container-body-content {
  width: 85%;
  height: 100%;
  margin: 20px auto;
  display: flex;

}

.apply-container-body-content-submit {
  width: 100%;
  height: 40px;
  display: flex;
  justify-content: flex-end;
  margin-bottom: 20px;
}

.apply-container-footer {
  width: 95%;
  height: 10px;
  margin: 0 auto;
}
</style>